package com.lzy.business.controller.agent;

import com.lzy.business.controller.BaseController;
import com.lzy.business.request.AgentSystemRequest;
import com.lzy.business.response.AgentSystemResponse;
import com.lzy.framework.core.output.Result;
import com.lzy.framework.core.utils.DozerUtils;
import com.lzy.product.apis.AgentSystemServiceApi;
import com.lzy.product.dtos.agent.AgentSystemDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by WIN7 on 2018/4/13.
 */
@Controller
@RequestMapping("/admin/agent/system")
public class AgentSystemController extends BaseController {

    @Autowired
    private AgentSystemServiceApi agentSystemServiceApi;


    @RequestMapping(value = "", method = RequestMethod.GET)
    public String view() {
        return "agent/order/agent_list";
    }


    /**
     * 查询体系列表
     */
    @ResponseBody
    @RequestMapping(value = "/queryAgentSystem", method = RequestMethod.GET)
    public List<AgentSystemResponse> queryAgentSystem(AgentSystemRequest request) {
        List<AgentSystemDto> list = agentSystemServiceApi.queryAgentSystemList(DozerUtils.map(request, AgentSystemDto.class));
        return DozerUtils.maps(list,AgentSystemResponse.class);
    }

    /**
     * 查询体系明细
     */
    @ResponseBody
    @RequestMapping(value = "/queryAgentSystemById", method = RequestMethod.GET)
    public Result queryAgentSystemById(Long id) {
        AgentSystemDto agentSystemDto = agentSystemServiceApi.findById(id);
        return new Result(agentSystemDto);
    }


    /**
     * 创建体系
     */
    @ResponseBody
    @RequestMapping(value = "/createAgentSystem", method = RequestMethod.GET)
    public Result createAagntProduct(AgentSystemDto agentSystem) {
        agentSystem.setCreateUser(getLoginUserID());
        agentSystem.setUpdateUser(getLoginUserID());
        agentSystemServiceApi.insert(agentSystem);
        return new Result();
    }


    /**
     * 更新体系
     */
    @ResponseBody
    @RequestMapping(value = "/updateAgentSystem", method = RequestMethod.GET)
    public Result updateAgentSystem(AgentSystemDto agentSystem) {
        agentSystemServiceApi.update(agentSystem);
        return new Result();

    }


    /**
     * 删除体系
     */
    @ResponseBody
    @RequestMapping(value = "/deleteAgentSystem", method = RequestMethod.GET)
    public Result deleteAgentSystem(Long id) {
        agentSystemServiceApi.delete(id);
        return new Result();

    }
}
